<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge，chrome=1">

    <title>用户关系管理</title>

    <link rel="stylesheet" href="/static/css-lib/bootstrap.min.css" />
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="table-responsive">
                <table class="table table-bordered table-hover table-condensed">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>学生</th>
                            <th>年级</th>
                            <th>科目</th>
                            <th>老师</th>
                            <th>家长</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach var="Relationship" items="${RelationshipList}" varStatus="status">
                            <tr>
                                <td>${status.count}</td>
                                <c:choose>
                                    <c:when test="${empty Relationship.studentRealName}">
                                        <td>${Relationship.studentName}</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td>${Relationship.studentRealName}</td>
                                    </c:otherwise>
                                </c:choose>
                                <td>【${Relationship.gradeSec}】${Relationship.grade}</td>
                                <td>${Relationship.subjectName}</td>
                                <c:choose>
                                    <c:when test="${empty Relationship.teacherRealName}">
                                        <td>${Relationship.teacherName}</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td>${Relationship.teacherRealName}</td>
                                    </c:otherwise>
                                </c:choose>
                                <c:choose>
                                    <c:when test="${empty Relationship.parentsRealName}">
                                        <td>${Relationship.parentsName}</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td>${Relationship.parentsRealName}</td>
                                    </c:otherwise>
                                </c:choose>
                                <td data-id="<c:out value="${Relationship.relationId}" />">
                                    <button type="button" class="btn btn-default">详情</button>
                                    <button name="manager" type="button" class="btn btn-default">管理</button>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="/static/js-lib/jquery-3.4.1.min.js"></script>
    <script>
        (function ($) {
            "use strict";

            let managerBtn = $("[name='manager']");
            managerBtn.on("click",function (ev) {
                let event = ev || window.event;
                let target = event.target || event.srcElement;

                let relationId = $(target).parent("td").attr("data-id");
                if(relationId === undefined || relationId === null){
                    alert("不能获取到属性值");
                }else{
                    window.top.changeIframe("/admin/frame/managerRelationship?id="+relationId);
                }
            });
        })(window.jQuery);
    </script>
</body>
</html>